"""添加@人功能字段

Revision ID: add_at_persons_field
Revises: 8358f5338d96
Create Date: 2025-07-20 15:30:00.000000

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'add_at_persons_field'
down_revision = '8358f5338d96'
branch_labels = None
depends_on = None

def upgrade():
    """升级：添加@人功能字段"""
    # 检查task_robot_association表是否存在at_persons字段
    connection = op.get_bind()
    inspector = sa.inspect(connection)
    columns = [col['name'] for col in inspector.get_columns('task_robot_association')]
    
    if 'at_persons' not in columns:
        # 添加at_persons字段
        op.add_column('task_robot_association', sa.Column('at_persons', sa.Text(), nullable=True))
        print("✅ 已添加at_persons字段到task_robot_association表")
    else:
        print("ℹ️  at_persons字段已存在，跳过添加")

def downgrade():
    """降级：移除@人功能字段"""
    # 移除at_persons字段
    op.drop_column('task_robot_association', 'at_persons')
    print("✅ 已移除at_persons字段") 